package com.cms.service;

import java.util.List;

import com.cms.model.ImportLog;
import com.service.AbstractDateService;
import com.utils.dbcp.ConnectionManager;
import com.utils.dbcp.ModelGenerator;

public class ImportLogServiceImpl extends AbstractDateService implements
		ImportLogService {

	@Override
	public List<ImportLog> getImportLog(String sdate, String edate) {
		String sql="select * from t_importlog where  createdate>='"+sdate
				+"' and createdate<='"+edate+" 23:59:59' " +
				" order by createdate desc";
		ModelGenerator<ImportLog> dbcpmg = new ModelGenerator<ImportLog>(ImportLog.class);
		return dbcpmg.generateList(base, sql);
	}

	@Override
	public ImportLog getImportLogById(int id) {
		String sql="select * from t_importlog where id = '"+id+"' order by createdate desc";
		ModelGenerator<ImportLog> dbcpmg = new ModelGenerator<ImportLog>(ImportLog.class);
		return dbcpmg.generate(base, sql);
	}

	@Override
	public boolean insertImportLog(ImportLog model) {
		model.setId(getTableId("t_importlog"));
		String sql = 
			"insert into t_importlog(id,filename,refilename,filesrc,createuser,createdate) " +
			"values(" + String.valueOf(model.getId()) + ",'"+model.getFilename()+"','"+model.getRefilename()+"','" 
			+ encodeDb(model.getFilesrc()) + "','" + model.getCreateuser() + "','" + 
					model.getCreatedate() + "')";
		return ConnectionManager.getInstance().execute(base,sql);
	}

}
